package com.logger.services;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;

import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import com.logger.persistance.dao.TransactionStateDAO;
import com.logger.persistance.dao.imp.GenericDaoHibernate;
import com.logger.persistance.model.TransactionState;

public class test {

   
    public static void main(String[] args) throws InstantiationException, IllegalAccessException, ClassNotFoundException, SQLException {

        testDB();
        ApplicationContext appContext = new ClassPathXmlApplicationContext("classpath:/applicationContext.xml");

         TransactionStateDAO transactionStateDao = appContext.getBean(TransactionStateDAO.class);
         TransactionState ts=new TransactionState();
         ts.setTransactionStateID(0);
         ts.setTransactionStateLABEL("Error");
         transactionStateDao.addTransactionState(ts);
         //transactionStateDao.deleteTransactionState(0);
         System.out.println("###########");

    }

    private static void testDB() throws InstantiationException, IllegalAccessException, ClassNotFoundException, SQLException {
        // TODO Auto-generated method stub

        final String userName = "root";
        final String password = "";
        final String url = "jdbc:mysql://localhost/logparserdb";
        Class.forName("com.mysql.jdbc.Driver").newInstance();
        Connection conn = DriverManager.getConnection(url, userName, password);
        System.out.println("Database connection established");
    }

}